<?php

class NewsModel extends Model{
	public $id;
	public $header;
	public $description;
	public $body;
	public $date;
	
	function SelectNewsFromSql($id){
		$temp = $this->db->query("SELECT * FROM news WHERE id= ?", array($id), $fetch = FALSE, $bindType = TRUE);
		$this->id = $temp[0]['id'];
		$this->header = $temp[0]['header'];
		$this->description = $temp[0]['description'];
		$this->body = $temp[0]['body'];
		$this->date = $temp[0]['date'];
	}
	
	function SelectAllNewsFromSql(){
		$temp = $this->db->query("SELECT * FROM news ORDER BY id DESC", array($id), $fetch = FALSE, $bindType = TRUE);
		return $temp;
	}
	
	function UpdateNewsInSql(){
		$temp = $this->db->query('UPDATE news SET header=?, description=?, body=?, date=? WHERE id= ?', array($this->header, $this->description, $this->body, $this->date, $this->id), $fetch = FALSE, $bindType = TRUE);
	}
	
	function InsertNewsToSql(){
		try{
			$stmt = $this->db->sqldb->prepare("INSERT INTO news (header, description, body, date) VALUES (:header, :description,    
					:body, :date)");
			$stmt->bindParam(':header', $this->header);
			$stmt->bindParam(':description', $this->description);
			$stmt->bindParam(':body', $this->body);
			$stmt->bindParam(':date', $this->date);
			$stmt->execute();
		}catch(PDOException $error){
			$db->rollBack();
		}	
	}
	
	function DeleteNewsFromSql($id){
		$temp = $this->db->query('DELETE FROM news WHERE id= ?', array($id), $fetch = FALSE, $bindType = TRUE);
	}
	
	function SetId($id){
		return $this->id = $id;
	}
	
	function GetId(){
		return $this->id;
	}
	
	function SetHeader($header){
		return $this->header = $header;
	}
	
	function GetHeader(){
		return $this->header;
	}
	
	function SetDescription($description){
		return $this->description = $description;
	}
	
	function GetDescription(){
		return $this->description;
	}
	
	function SetBody($body){
		return $this->body = $body;
	}
	
	function GetBody(){
		return $this->body;
	}	
	
	function SetDate($date){
		return $this->date = $date;
	}
	
	function GetDate(){
		return $this->date;
	}	
	
	public function LastNews(){
		$news = $this->db->query("SELECT id, header, description, body, date FROM news ORDER BY id DESC LIMIT 5", array(), $fetch = FALSE, $bindType = TRUE);
		return $news;
	}
	
}
//áéáéá
